import request from "@/utils/request";

//1.获取一级列表
//返回值每一项类型
export interface reqCategoryRenturnItemType {
  id: number;
  name: string;
  category1Id?: number;
  category2Id?: number;
}
//返回值类型
export type reqCategoryRenturnType = reqCategoryRenturnItemType[];
//请求一级列表
export const requestCategoryList1 = () => {
  return request.get<any, reqCategoryRenturnType>(
    "/admin/product/getCategory1"
  );
};

//2.获取二级列表
export const requestCategoryList2 = (category1Id: number) => {
  return request.get<any, reqCategoryRenturnType>(
    `/admin/product/getCategory2/${category1Id}`
  );
};

//3.获取三级列表
export const requestCategoryList3 = (category2Id: number) => {
  return request.get<any, reqCategoryRenturnType>(
    `/admin/product/getCategory3/${category2Id}`
  );
};

//4.获取品牌属性信息
//返回值中attrValueList的每一项
export interface reqAttrReturnAttrValueType {
  id?: number;
  valueName: string;
  attrId: number | undefined;
  isEdit?: boolean
}
//返回值每一项类型
export interface reqAttrReturnItemType {
  id?: number;
  attrName: string;
  categoryId: number;
  categoryLevel: number;
  attrValueList: reqAttrReturnAttrValueType[],
  attrIdValueId?: string
}
//返回值类型
export type reqAttrReturnType = reqAttrReturnItemType[]
//获取属性信息
export const requestAttrInfo = (
  category1Id: number,
  category2Id: number,
  category3Id: number
) => {
  return request.get<any,reqAttrReturnType>(
    `/admin/product/attrInfoList/${category1Id}/${category2Id}/${category3Id}`
  );
};

//修改或添加属性
export const requestUpdateOrAddAttr = (attrInfo:reqAttrReturnItemType) => {
    return request.post<any,null>('/admin/product/saveAttrInfo',attrInfo)
}

//删除属性
export const requestDeleteAttr = (attrId:number) => {
    return request.delete<any,null>(`/admin/product/deleteAttr/${attrId}`)
}
